<?php
require_once("DB.class.php");

class LogInserter{
	public static $DELETE = 2;
	public static $INSERT = 1;
	public static $EDIT = 3;
	
	private static $ecpairs = array(
		'certificationNumber'   => '产品质量证明书号',	
		'certificationCodification'	=> '产品质量证明书编号',		
		'sequenceNumber'              => '批次',
		'manufactory'	        => '生产厂家',						
		'authenticationMark'	        => '船级',					
		'steelNumber'            =>  '材质',						
		'size1'            =>  '厚',						
		'size2'			    =>  '宽',						
		'size3'	            =>  '长',						
		'count'	            =>  '数量',						
		'unitWeight'	            =>  '单重',						
		'orderNumber'	            =>  '订单号',						
		'orderSubitemNumber'	        =>  '订单子项号',						
		'unitPrice'          =>	'受订单价',						
		'materialNumber'            =>  '物料号',
		'consignmentBatch'			=>  '发货批次',			
		'sampleBatch'	        =>  '批号',						
		'facheNumber'	        =>  '发车证书号',					
		'purchaseNumber'     	    =>  '购单号',						
		'shipmentDate'           =>  '发货时间',								
		'month'			=>	'合同月份',						
		'vehicleNumber'	            =>  '车号',						
		'consignee'  	=>  '销售产家',						
		'remark'	        =>  '备注'); 
	
	private function log($content, $type){
		if(empty($content)){
			return;
		}
		
		$logcontent = array();
		$subLogcontent = array();
		
		if (is_array($content)){
			foreach($content as $key => $val){
				if(empty($val)){
					continue;
				}
				
				if(is_array($val)){
					$subLogcontent = array();
					foreach($val as $subkey => $subval){
						isset(self::$ecpairs[$subkey]) ? array_push($subLogcontent, self::$ecpairs[$subkey] . " : " . $subval) : null;
					}
					if($key == 0){
						$contentStr = join("，", $subLogcontent);					
					}else if($key ==1){
						$contentStr2 = join("，", $subLogcontent);
					}
				}else{
					isset(self::$ecpairs[$key]) ? array_push($logcontent, self::$ecpairs[$key]." : ".$val) : null;
				}
			}
		}else{
			$contentStr = "$content";
		}
		
		if($type ==3){
			$query = "insert into little_log
			set time = now(), content = '$contentStr', content2 = '$contentStr2', type = $type";
		}else{
			$query = "insert into little_log
			set time = now(), content = '$contentStr', type = $type";
		}
		DB::query($query);
	}
	
	public function logForInsert($content){
		self::log($content, self::$INSERT);
	}
	
	public function logForDelete($content){
		self::log($content, self::$DELETE);
	}
	
	public function logForEdit($content){
		self::log($content, self::$EDIT);
	}

}
?>